package visualization.jankenpon;

import java.awt.Graphics;
import java.util.Arrays;

import org.jfree.chart.ChartPanel;

import optimizers.commons.GAConstants;
import optimizers.ganeat.jankenpon.ConstantsJankenpon;

import visualization.PlotExpData;

public class JankenponPlotExpData extends PlotExpData {

	ChartPanel chartPanel;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	protected String[] geneNames;

	protected double[][] expData;
	
	public JankenponPlotExpData(String title, double[][] expData, String geneNames[], String fName, String xAxis) {
		super(title, expData, geneNames, fName ,xAxis);
		chartPanel = (ChartPanel) super.getComponent(0);
		this.geneNames = geneNames;
		this.expData = expData;
	}

	public void paint(Graphics g){
		super.paint(g);
		double domainSize = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea().getWidth();
		double rangeSize = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea().getHeight();
		int time = ConstantsJankenpon.initialTime;
		
		for(int i=0; i< ConstantsJankenpon.rounds; i++){
			time += ConstantsJankenpon.fightTime;
			double jan = expData[Arrays.asList(geneNames).indexOf(ConstantsJankenpon.JANSTRING)][time-1];
			double ken = expData[Arrays.asList(geneNames).indexOf(ConstantsJankenpon.KENSTRING)][time-1];
			double pon = expData[Arrays.asList(geneNames).indexOf(ConstantsJankenpon.PONSTRING)][time-1];
			String iplayed = "";
			if(jan > ken + ConstantsJankenpon.playThreshold && jan > pon + ConstantsJankenpon.playThreshold){
				iplayed = ConstantsJankenpon.JANSTRING;
			} else if (ken > jan + ConstantsJankenpon.playThreshold && ken > pon + ConstantsJankenpon.playThreshold){
				iplayed = ConstantsJankenpon.KENSTRING;
			} else if (pon > jan + ConstantsJankenpon.playThreshold && pon > ken + ConstantsJankenpon.playThreshold){
				iplayed = ConstantsJankenpon.PONSTRING;
			} 
			jan = expData[Arrays.asList(geneNames).indexOf(ConstantsJankenpon.contestantPrefix+ConstantsJankenpon.JANSTRING)][time-1];
			ken = expData[Arrays.asList(geneNames).indexOf(ConstantsJankenpon.contestantPrefix+ConstantsJankenpon.KENSTRING)][time-1];
			pon = expData[Arrays.asList(geneNames).indexOf(ConstantsJankenpon.contestantPrefix+ConstantsJankenpon.PONSTRING)][time-1];
			String opponentplayed = "";
			if(jan > ken + ConstantsJankenpon.playThreshold && jan > pon + ConstantsJankenpon.playThreshold){
				opponentplayed = ConstantsJankenpon.JANSTRING;
			} else if (ken > jan + ConstantsJankenpon.playThreshold && ken > pon + ConstantsJankenpon.playThreshold){
				opponentplayed = ConstantsJankenpon.KENSTRING;
			} else if (pon > jan + ConstantsJankenpon.playThreshold && pon > ken + ConstantsJankenpon.playThreshold){
				opponentplayed = ConstantsJankenpon.PONSTRING;
			} 
			g.drawString(iplayed+":"+opponentplayed, (int) Math.round(domainSize *((double)time)/((double) model.Constants.numberOfPoints)), 100);
		}
	}
}
